<!DOCTYPE html>
<html lang="en">
<include file="CommonSidebar:common-head"/>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/css/common.css">
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>


<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-md-12">
                <h1 class="page-header">所有用户购书订单</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                    <div class="panel panel-default">
                        <div class="panel-heading" role="tab" id="headingOne">
                            <h4 class="panel-title">
                                <a role="button" data-toggle="collapse" data-parent="#accordion"
                                   href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                    搜索栏
                                </a>
                            </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse " role="tabpanel"
                             aria-labelledby="headingOne">
                            <div class="panel-body">
                                <form action="{:U('Index')}" class="form-horizontal" method="get">
                                    <input type="hidden" name="order_type" value="{$CSDATA.order_type}">
                                    <input type="hidden" name="order_id" value="{$CSDATA.order_id}">

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">订单CODE</label>

                                        <div class="col-sm-4">
                                            <input class="form-control" name="order_code" value="{$CSDATA.order_code}">
                                        </div>
                                        <label class="col-sm-2 control-label">收货人手机</label>

                                        <div class="col-sm-4">
                                            <input class="form-control" name="order_phone"
                                                   value="{$CSDATA.order_phone}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">收货人名称</label>

                                        <div class="col-sm-4">
                                            <input class="form-control" name="order_address_name"
                                                   value="{$CSDATA.order_address_name}">
                                        </div>
                                        <label class="col-sm-2 control-label">物流单号</label>

                                        <div class="col-sm-4">
                                            <input class="form-control" name="order_express_go"
                                                   value="{$CSDATA.order_express_go}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-10 col-sm-offset-2">
                                            <button type="submit" class="btn  btn-primary">筛选</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.row -->

        <div class="row">
            <div class="col-md-12">
                <div class="btn-group btn-group-justified" role="group" aria-label="">
                    <foreach name="ORDER_STATE_SHOW" item="v" key="k">
                        <a id="state{$k}" href="{:U('Order/index')}?order_type={$k}" type="button"
                           class="btn btn-default">{$v}</a>
                    </foreach>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">

                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <include file="Extends/searchForUser"/>
                                <thead>
                                <tr>
                                    <th style="text-align:center"><input name="all_checkbox" type='checkbox'
                                                                         id="all_checkbox"></th>
                                    <th class="text-center GridSortTh" width="11%" data-order="ISBN">订单编号</th>
                                    <th style="text-align:center">商品</th>
                                    <th style="text-align:center" width="15%" class="text-center GridSortTh"
                                        data-order="TITLE">收货信息
                                    </th>

                                    <th style="text-align:center" class="text-center GridSortTh" data-order="PRESS">
                                        本数
                                    </th>
                                    <th style="text-align:center" class="text-center GridSortTh"
                                        data-order="PACKING_SPECIFICATION" width="6%">定价和
                                    </th>
                                    <th style="text-align:center" class="text-center GridSortTh" data-order="Y_PRICE"
                                        width="15%">订单价格计算
                                    </th>
                                    <th style="text-align:center" width="10%" class="text-center GridSortTh"
                                        data-order="OPENID" width="6%">余额支付
                                    </th>

                                    <th style="text-align:center" width="10%" class="text-center GridSortTh"
                                        data-order="OPENID" width="6%">支付总金额
                                    </th>
                                    <th style="text-align:center" width="10%" class="text-center GridSortTh"
                                        data-order="OPENID">订单开始时间
                                    </th>
                                    <th style="text-align:center" width="10%" class="text-center GridSortTh"
                                        data-order="OPENID">物流单号
                                    </th>
                                    <th style="text-align:center" width="20%">备注</th>
                                </tr>
                                </thead>
                                <tbody>
                                <foreach name="data" item="v">
                                    <tr>
                                        <td><input type='checkbox' name='checkbox'></td>
                                        <td onclick="showBook($(this));">{$v.order_code}<br/><br/>{$v.order_id}</td>
                                        <td>
                                            <table hidden frame="void" width="200" border="1" cellspacing="0"
                                                   cellpadding="0">
                                                <foreach name="v.order_books" item="v1">
                                                    <if condition="$v1.state == 0">
                                                        <input name="red" type="hidden" value="1">
                                                    </if>
                                                    <tr>
                                                        <td>
                                                            <div>
                                                                <img style="height: 120px;width:100px"
                                                                     src="{$v1.ob_book_pic}">
                                                            </div>
                                                            <div><span>{$v1.ob_name}</span></div>
                                                            <div><span class="text-muted">{$v1.ob_book_gg}</span></div>
                                                        </td>
                                                        <td width="100px">
                                                            <div><span class="text-muted">定价:{$v1.ob_old_money}</span>
                                                            </div>
                                                            <div><span
                                                                    class="text-success">销售价:{$v1.ob_pay_money}</span>
                                                            </div>
                                                            <p>{$v1.ob_num} 件</p>
                                                            <if condition="$CSDATA.order_type gt 1">
                                                                <if condition="$v1.state == 0">
                                                                    <p onclick='ckwz("{$v1.book_gg_id}","{$v1.ob_id}",$(this))'
                                                                       class="btn btn-warning btn-xs">请先出库</p>
                                                                    <else/>
                                                                    <span style="color: red;font-size:70%">{$v1.info}</span>
                                                                </if>
                                                            </if>
                                                        </td>
                                                    </tr>
                                                </foreach>
                                            </table>
                                        </td>
                                        <td>
                                            <a target="_blank" class="btn btn-warning btn-xs"  href="{:U('User/Index')}?user_id={$v.user_id}">{$v.user_wx_name}</a><br/>
                                            {$v.order_address_name}<br/>{$v.order_phone}<br/>{$v.order_address}
                                        </td>
                                        <td>{$v.order_num}</td>
                                        <td>{$v.order_old_money}</td>
                                        <td>
                                            <div style="color: #FF9900"><span>书籍售价和:+</span>{$v.order_book_money}</div>
                                            <div style="color: #FF9900"><span>邮费:+</span>{$v.order_postage}</div>
                                            <div style="color: forestgreen"><span>优惠金额:-</span>{$v.order_yh_money}</div>
                                        </td>
                                        <td style="color: blue">{$v.order_ye_pay_money}</td>
                                        <td style="color: red" onclick='updateOrderMoney("{$v.order_id}",$(this))'>
                                            {$v.order_money}
                                        </td>
                                        <td>{$v.order_start_time}</td>
                                        <td>
                                            <if condition="$CSDATA.order_type == 2">
                                                <span onclick='ShowKdModle($(this),"{$v.order_id}")'
                                                      class="btn btn-warning btn-xs">填写订单号</span>
                                                <else/>
                                            </if>
                                            <a style="color: red"onclick='ShowKdModle($(this),"{$v.order_id}","{$v.order_express_go_name}","{$v.order_express_go}")'>
                                            {$v.order_express_go_name}<br/>
                                            {$v.order_express_go}
                                            </a>
                                        </td>
                                        <td>
                                            <if condition="outS('USER_NAME') == 'mao'">
                                                <a href="{:U('Order/WDelOrder')}?order_id={$v.order_id}" class="btn btn-danger btn-xs" >伪删除</a><br/>
                                            </if>
                                            <span style="background-color: rgb(1, 122, 204);" class="btn btn-default">{$v.StateShow}</span><br/>
                                            <span style="color: red;">{$v.order_user_remarks}</span><br/>
                                            <span onclick="AddAdminRemarks('{$v.order_id}','{$v.order_remarks}')"
                                                       class="btn btn-warning btn-xs">管理员修改/添加备注</span> <br/>
                                            {$v.order_remarks}
                                        </td>

                                    </tr>
                                </foreach>
                                </tbody>
                            </table>
                            <div class="blue">{$show}</div>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->
</div>


<!--快递单号-->
<div id="KDDH" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">填写快递信息</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <input id="dk_order_id" type="hidden" name="order_id" value="">

                        <div class="col-xs-12">
                            <label>快递公司</label>
                            <select class="rugby-login form-control" id="KDNAME">
                                <foreach name="KDGS" item="v" key="k">
                                    <option value="{$v['region_name']}">{$v['region_name']}</option>
                                </foreach>
                            </select>
                        </div>
                        <div class="col-xs-12">
                            <label>订单号</label>
                            <input class="rugby-login form-control" id="KDCODE">
                        </div>
                        <div class="col-xs-6 modal-footer">
                            <button onclick="OrderFH()" class="btn btn-block btn-primary">保存</button>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<!--快递单号-->

<!--修改订单金额-->
<div id="allayModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">修改订单金额</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <input id="order_id" type="hidden" name="order_id" value="">

                        <div class="col-xs-12">
                            <label>订单金额</label>
                            <input id="order_money" name="order_money" class="rugby-login form-control" value="">
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button onclick="updatecost()">
                    确认
                </button>
            </div>
        </div>
    </div>
</div>
<!--修改订单金额-->
<!--查看位置-->
<div id="WZModal" class="modal fade bs-example-modal-sm" data-backdrop='static' tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true" style="font-size:35px">&times;</span></button>
                <h3 class="modal-title text-center">书籍位置</h3>
            </div>
            <div class="modal-body" style="padding-top:0px;padding-bottom:5px;">
                <div class="row" style="height:530px;overflow-y:scroll;">
                    <div class=" spell-list"
                         style="height:100%; background:#f0f0f0; overflow-y:scroll; overflow-x:hidden; -webkit-overflow-scrolling:touch">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="panel-body">
                                    <div class="dataTable_wrapper">
                                        <table class="table table-striped table-bordered table-hover"
                                               id="dataTables-example">
                                            <thead>
                                            <tr>
                                                <th style="text-align: center">仓库</th>
                                                <th style="text-align:center">书架</th>
                                                <th style="text-align:center">书柜</th>
                                                <th style="text-align:center">移除</th>
                                            </tr>
                                            </thead>
                                            <tbody id="WZDATA">

                                            </tbody>
                                        </table>
                                    </div>
                                    <!-- /.table-responsive -->
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--查看位置-->

<!--修改订单备注-->
<div id="AddAdminRemarks" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">管理员修改/添加备注</h4>
            </div>
            <form action="{:U('AddOrderRemarks')}" method="post">
                <div class="modal-body">
                    <div class="container-fluid">
                        <div class="row">
                            <input id="o_id" type="hidden" name="order_id" value="">

                            <div class="col-xs-12">
                                <label>备注信息</label>
                                <textarea rows="5" id="order_remarks" name="order_remarks" class="rugby-login form-control" value=""></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit">
                        确认
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--修改订单备注-->


<include file="CommonSidebar:common-script"/>
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>

<script>
//添加管理员备注弹窗
function AddAdminRemarks(o_id,order_remarks){
    $('#o_id').val(o_id);
    $('#order_remarks').val(order_remarks);
    $('#AddAdminRemarks').modal('show');
}

    //导航显示订单状态
    $('#state' + ({$CSDATA['order_type']})).css('background-color', '#0000cc');
    //显示商品
    function showBook(elem) {
        var top = elem.next().find('table');
        if (top.is(":hidden")) {
            top.show();
        } else {
            top.hide();
        }
    }

    //    查看书籍位置
    var wz_this='';
    function ckwz(ID, OB_ID,elem) {
        wz_this = elem;
        $.post("{:U('Book/GetBookWZ')}",
                {ID: ID},
                function (data) {
                    console.log(data);
                    var html = '';
                    $("#WZDATA").html("");
                    for (var i = 0; i < data.length; i++) {
                        html += "<tr class='odd gradeX' > " +
                                "<td class='enter' style='text-align:center'> "
                                + data[i]['P']
                                + data[i]['C']
                                + data[i]['Z']
                                + data[i]['ADDRESS']
                                + data[i]['NAME'] +
                                "</td> " +
                                "<td class='center' style='text-align:center'> "
                                + data[i]['SJCODE'] +
                                "</td> " +
                                "<td class='center' style='text-align:center'> "
                                + data[i]['SGCODE'] +
                                "</td> " +
                                "<td class='center' style='text-align:center'><a onclick='ycwz(\"" + data[i]['BOOK_WZ_ID'] + "\",\"" + OB_ID + "\",$(this))'> 出库</a></td> " +
                                "</tr>";
                    }
                    $("#WZDATA").append(html);
                    $("#WZModal").modal("show");
                });
    }
    //书籍出库移除位置
    function ycwz(WZ_ID, OB_ID, elem) {
        $.post("{:U('bookck')}",
                {WZ_ID: WZ_ID, OB_ID: OB_ID},
                function (data) {
                    console.log(data);
                    if (data == 1) {
                        alert('出库成功');
                        wz_this.remove();
                        $('#WZModal').modal('hide');
                    } else {
                        alert('出库失败');
                    }
                });
    }

    //填写快递信息
    function ShowKdModle(elem, order_id,name,code) {
        var red = elem.parent().parent().find('table').find('input').val();
        if (red == 1) {
            alert('请先书籍出库再填写快递单号');
        } else {
            $('#KDDH').modal("show");
            $('#dk_order_id').val(order_id);
            $('#KDNAME').val(name);
            $('#KDCODE').val(code);
        }
    }
    //订单发货 kd_type =1 是回收订单
    function OrderFH() {
        var KDNAME = $('#KDNAME').val();
        var KDCODE = $('#KDCODE').val();
        var id = $('#dk_order_id').val();
        $.post("{:U('Order/FHhanld')}", {
            order_id: id,
            KDNAME: KDNAME,
            KDCODE: KDCODE,
            TYPE: 2
        }, function (OK) {
            if (OK) {
                alert('添加快递信息成功');
                window.location.reload();
            } else {
                alert('添加快递信息失败');
            }
        });

    }
</script>

<script>
    var elem_all = '';
    //修改订单价格弹窗
    function updateOrderMoney(ID, elem) {
        if ('{$CSDATA.order_type}'==1){
            elem_all = elem;
            $("#order_id").val(ID);
            $("#order_money").val(jQuery.trim(elem.html()));
            $("#allayModal").modal("show");
        }

    }
    //修改订单价格处理
    function updatecost() {
        var ID = $("#order_id").val();
        var money = $("#order_money").val();

        if (confirm("确认修改？")) {
            $.post("{:U('updatecost')}",
                    {ID: ID, money: money},
                    function (data) {
                        console.log(data);
                        if (parseInt(data) == 1) {
                            alert('修改成功');
                            elem_all.html(money);
                        } else {
                            alert('修改失败');
                        }
                    });
            $("#allayModal").modal("hide");
        }
    }
</script>
</body>
</html>
